package cn.geodata.dataview;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.Date;

import cn.geodata.common.ConnectionPool;
import cn.geodata.database.DataFactory;
import cn.geodata.database.DataObject;

public class FireFactory extends DataFactory {
	public FireFactory(){
		this.editFieldList.add("path");
		this.editFieldList.add("row");
		this.editFieldList.add("sensor");
		this.editFieldList.add("source");
		this.editFieldList.add("dir");
		this.editFieldList.add("date");
		this.editFieldList.add("note");
		this.editFieldList.add("cloud");
		this.editFieldList.add("quality");
	}
	
	@Override
	protected Connection getConnection() throws Exception {
		return ConnectionPool.createInstance().getConnection("Data.View");
	}

	@Override
	protected String getTableName() {
		return "fire";
	}

	@Override
	protected DataObject readRecordEx(ResultSet res) throws Exception {
		Fire _data = new Fire();
		
		_data.setPath(res.getInt("path"));
		_data.setRow(res.getInt("row"));
		_data.setSensor(res.getString("sensor"));
		_data.setSource(res.getString("source"));
		_data.setDir(res.getString("dir"));
		_data.setDate(new Date(res.getDate("date").getTime()));
		_data.setNote(res.getString("note"));
		_data.setCloud(res.getFloat("cloud"));
		_data.setQuality(res.getString("quality"));
		
		return _data;
	}

	@Override
	protected void updateRecordEx(PreparedStatement prep, DataObject data)
			throws Exception {
		Fire _data = (Fire)data;
		
		prep.setInt(this.getEditFieldIndex("path") + 1, _data.getPath());
		prep.setInt(this.getEditFieldIndex("row") + 1, _data.getRow());
		prep.setString(this.getEditFieldIndex("sensor") + 1, _data.getSensor());
		prep.setString(this.getEditFieldIndex("source") + 1, _data.getSource());
		prep.setString(this.getEditFieldIndex("dir") + 1, _data.getDir());
		prep.setDate(this.getEditFieldIndex("date") + 1, new java.sql.Date(_data.getDate().getTime()));
		prep.setString(this.getEditFieldIndex("note") + 1, _data.getNote());
		prep.setFloat(this.getEditFieldIndex("cloud") + 1, _data.getCloud());
		prep.setString(this.getEditFieldIndex("quality") + 1, _data.getQuality());
	}
}
